package com.yixun.qfbao.response.premises;

import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

import org.springframework.util.CollectionUtils;

import com.yixun.qfbao.response.premises.detail.UrlInfo;
import com.yixun.qfbao.response.premises.detail.util.SplitHtmlUtil;
import com.yixun.qfbao.xf.model.PremisesDynamic;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author zilong.liu
 * @date 2020-8-13
 * 		楼盘动态
 */
@Data
public class PremisesDynamicResDto {
	
	public PremisesDynamicResDto() {
	}
	
	@SuppressWarnings("unchecked")
	public PremisesDynamicResDto(PremisesDynamic premisesDynamic) {
		this.title = premisesDynamic.getTitle();
		this.id = premisesDynamic.getId();
		this.updateTime = new SimpleDateFormat("yyyy.MM.dd").format(premisesDynamic.getUpdateTime());
		Map<String, Object> resMap;
		try {
			resMap = new SplitHtmlUtil().splitHtml(URLDecoder.decode(premisesDynamic.getContent(), "utf-8"));
		} catch (Exception e) {
			resMap = new SplitHtmlUtil().splitHtml(premisesDynamic.getContent());
		}
		if(resMap != null && resMap.get("content") != null) {
			this.content = (String) resMap.get("content");
		}
		if(resMap != null && resMap.get("urlInfoList") != null) {
			this.urlInfoList =  (List<UrlInfo>)resMap.get("urlInfoList");
		}
		SplitHtmlUtil.getRealUrlInfoList(urlInfoList);
	}
	
	
	@ApiModelProperty(value = "标题")
	private String title;
	
	@ApiModelProperty(value = "修改时间")
	private String updateTime;
	
	@ApiModelProperty(value = "内容")
	private String content;
	
	@ApiModelProperty(value = "视频以及图片信息集合")
	private List<UrlInfo> urlInfoList;

	@ApiModelProperty(value = "id")
	private Long id;
	
}
